<template>
	<view>
		<cu-custom bgColor="bg-gradual-pink" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">修改手机号码</block>
		</cu-custom>
		<form>
            <view class="cu-form-group margin-top">
				<view class="title">旧号码</view>
				<input placeholder="请输入旧号码" name="input" v-model="myFormData.oldphone"></input>
				<view class="cu-capsule radius">
					<view class='cu-tag bg-blue '>
						+86
					</view>
					<view class="cu-tag line-blue">
						中国大陆
					</view>
				</view>
			</view>
            <view class="cu-form-group margin-top">
				<view class="title">新号码</view>
				<input placeholder="请输入新号码" name="input" v-model="myFormData.newphone"></input>
				<view class="cu-capsule radius">
					<view class='cu-tag bg-blue '>
						+86
					</view>
					<view class="cu-tag line-blue">
						中国大陆
					</view>
				</view>
			</view>
            <view class="cu-form-group">
				<view class="title">密码</view>
				<input placeholder="请输入密码进行确认" name="input" v-model="myFormData.password" disabled></input>
			</view>
			<view class="padding flex flex-direction">
				<button class="cu-btn bg-blue lg"  @click="onSubmit">确定</button>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				myFormData:{
					oldphone:'',
                    newphone: '',
                    phone: '',
                    password:''
				},
			};
		},
		onLoad: function (option) {
			console.log("this.$Route.query",this.$Route.query);
			let query=this.$Route.query
			if(query){
				this.myFormData=query;
				Object.keys(this.myFormData).map(key=>{
				  if(this.myFormData[key]=='无'){
					this.myFormData[key] = ''
				  }
				})
				console.log("this.myFormData",this.myFormData)
			}
		},
		methods: {
			onSubmit() {
			  let myForm = this.myFormData

			  if(!myForm.oldphone || myForm.oldphone.length==0){
				this.$tip.alert('请输入旧手机号');
				return false
                }
                if(!myForm.newphone || myForm.newphone.length==0){
				this.$tip.alert('请输入新手机号');
				return false
			  }
			  if(!checkPhone.test(myForm.phone)){
				this.$tip.alert('请输入正确的手机号');
				return false
                }
            if(!myForm.password || myForm.password.length==0){
				this.$tip.alert('请输入密码进行确认');
				return false
			  }
				this.$tip.loading();
				this.$http.put('/sys/user/appEdit',this.myFormData).then(res=>{
					console.log(res)
					this.$tip.loaded();
					if (res.data.success){
						this.$tip.toast('提交成功')
						this.$Router.replace({name:'people'})
						/* uni.navigateTo({
							url: '/pages/user/userdetail'
						}) */
					}
				}).catch(()=>{
					this.$tip.loaded();
					this.$tip.error('提交失败')
				});
			},
		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
</style>
